
#include <ALittleServer/LogSystem/LogSystem.h>
#include <ALittleServer/ScriptSystem/ScriptSystem.h>

#include <vector>
#include <boost/filesystem.hpp>
#include <stdlib.h>

unsigned int g_file_count = 0;
std::vector<std::string> g_file_list;

const char* Global_GetFileName(unsigned int index)
{
	if (index >= g_file_list.size()) return "";
	return g_file_list[index].c_str();
}

unsigned int Global_GetFileCount(const char* script_dir)
{
	if (!boost::filesystem::is_directory(script_dir))
		return 0;

	g_file_count = 0;

	boost::filesystem::recursive_directory_iterator it(script_dir);
	boost::filesystem::recursive_directory_iterator end;	
	for (; it != end; ++it)
	{
		if (boost::filesystem::is_directory(*it))
			continue;
		++ g_file_count;
		g_file_list.push_back(it->path().stem().string());
	}
	return g_file_count;
}

int main()
{
	ALittle::ScriptSystem script_system;
	script_system.Start();
	script_system.AddFunction("Global_GetFileCount", Global_GetFileCount);
	script_system.AddFunction("Global_GetFileName", Global_GetFileName);

	if (boost::filesystem::is_regular_file("ProtocolAnalyser.lua"))
		script_system.RunScriptFile("ProtocolAnalyser.lua");
	else
		ALITTLE_ERROR("can't find ProtocolAnalyser.lua file");

	script_system.Close();
	system("pause");
	return 0;
}